<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>range.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_math_range.js.html">range.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2006 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview A utility class for representing a numeric range.
<a name="line17"></a> */
<a name="line18"></a>
<a name="line19"></a>
<a name="line20"></a>goog.provide(&#39;goog.math.Range&#39;);
<a name="line21"></a>
<a name="line22"></a>
<a name="line23"></a>
<a name="line24"></a>/**
<a name="line25"></a> * A number range.
<a name="line26"></a> * @param {number} a One end of the range.
<a name="line27"></a> * @param {number} b The other end of the range.
<a name="line28"></a> * @constructor
<a name="line29"></a> */
<a name="line30"></a>goog.math.Range = function(a, b) {
<a name="line31"></a>  /**
<a name="line32"></a>   * The lowest value in the range.
<a name="line33"></a>   * @type {number}
<a name="line34"></a>   */
<a name="line35"></a>  this.start = a &lt; b ? a : b;
<a name="line36"></a>
<a name="line37"></a>  /**
<a name="line38"></a>   * The highest value in the range.
<a name="line39"></a>   * @type {number}
<a name="line40"></a>   */
<a name="line41"></a>  this.end = a &lt; b ? b : a;
<a name="line42"></a>};
<a name="line43"></a>
<a name="line44"></a>
<a name="line45"></a>/**
<a name="line46"></a> * @return {!goog.math.Range} A clone of this Range.
<a name="line47"></a> */
<a name="line48"></a>goog.math.Range.prototype.clone = function() {
<a name="line49"></a>  return new goog.math.Range(this.start, this.end);
<a name="line50"></a>};
<a name="line51"></a>
<a name="line52"></a>
<a name="line53"></a>if (goog.DEBUG) {
<a name="line54"></a>  /**
<a name="line55"></a>   * Returns a string representing the range.
<a name="line56"></a>   * @return {string} In the form [-3.5, 8.13].
<a name="line57"></a>   * @override
<a name="line58"></a>   */
<a name="line59"></a>  goog.math.Range.prototype.toString = function() {
<a name="line60"></a>    return &#39;[&#39; + this.start + &#39;, &#39; + this.end + &#39;]&#39;;
<a name="line61"></a>  };
<a name="line62"></a>}
<a name="line63"></a>
<a name="line64"></a>
<a name="line65"></a>/**
<a name="line66"></a> * Compares ranges for equality.
<a name="line67"></a> * @param {goog.math.Range} a A Range.
<a name="line68"></a> * @param {goog.math.Range} b A Range.
<a name="line69"></a> * @return {boolean} True iff both the starts and the ends of the ranges are
<a name="line70"></a> *     equal, or if both ranges are null.
<a name="line71"></a> */
<a name="line72"></a>goog.math.Range.equals = function(a, b) {
<a name="line73"></a>  if (a == b) {
<a name="line74"></a>    return true;
<a name="line75"></a>  }
<a name="line76"></a>  if (!a || !b) {
<a name="line77"></a>    return false;
<a name="line78"></a>  }
<a name="line79"></a>  return a.start == b.start &amp;&amp; a.end == b.end;
<a name="line80"></a>};
<a name="line81"></a>
<a name="line82"></a>
<a name="line83"></a>/**
<a name="line84"></a> * Given two ranges on the same dimension, this method returns the intersection
<a name="line85"></a> * of those ranges.
<a name="line86"></a> * @param {goog.math.Range} a A Range.
<a name="line87"></a> * @param {goog.math.Range} b A Range.
<a name="line88"></a> * @return {goog.math.Range} A new Range representing the intersection of two
<a name="line89"></a> *     ranges, or null if there is no intersection. Ranges are assumed to
<a name="line90"></a> *     include their end points, and the intersection can be a point.
<a name="line91"></a> */
<a name="line92"></a>goog.math.Range.intersection = function(a, b) {
<a name="line93"></a>  var c0 = Math.max(a.start, b.start);
<a name="line94"></a>  var c1 = Math.min(a.end, b.end);
<a name="line95"></a>  return (c0 &lt;= c1) ? new goog.math.Range(c0, c1) : null;
<a name="line96"></a>};
<a name="line97"></a>
<a name="line98"></a>
<a name="line99"></a>/**
<a name="line100"></a> * Given two ranges on the same dimension, determines whether they intersect.
<a name="line101"></a> * @param {goog.math.Range} a A Range.
<a name="line102"></a> * @param {goog.math.Range} b A Range.
<a name="line103"></a> * @return {boolean} Whether they intersect.
<a name="line104"></a> */
<a name="line105"></a>goog.math.Range.hasIntersection = function(a, b) {
<a name="line106"></a>  return Math.max(a.start, b.start) &lt;= Math.min(a.end, b.end);
<a name="line107"></a>};
<a name="line108"></a>
<a name="line109"></a>
<a name="line110"></a>/**
<a name="line111"></a> * Given two ranges on the same dimension, this returns a range that covers
<a name="line112"></a> * both ranges.
<a name="line113"></a> * @param {goog.math.Range} a A Range.
<a name="line114"></a> * @param {goog.math.Range} b A Range.
<a name="line115"></a> * @return {!goog.math.Range} A new Range representing the bounding
<a name="line116"></a> *     range.
<a name="line117"></a> */
<a name="line118"></a>goog.math.Range.boundingRange = function(a, b) {
<a name="line119"></a>  return new goog.math.Range(Math.min(a.start, b.start),
<a name="line120"></a>                             Math.max(a.end, b.end));
<a name="line121"></a>};
<a name="line122"></a>
<a name="line123"></a>
<a name="line124"></a>/**
<a name="line125"></a> * Given two ranges, returns true if the first range completely overlaps the
<a name="line126"></a> * second.
<a name="line127"></a> * @param {goog.math.Range} a The first Range.
<a name="line128"></a> * @param {goog.math.Range} b The second Range.
<a name="line129"></a> * @return {boolean} True if b is contained inside a, false otherwise.
<a name="line130"></a> */
<a name="line131"></a>goog.math.Range.contains = function(a, b) {
<a name="line132"></a>  return a.start &lt;= b.start &amp;&amp; a.end &gt;= b.end;
<a name="line133"></a>};
<a name="line134"></a>
<a name="line135"></a>
<a name="line136"></a>/**
<a name="line137"></a> * Given a range and a point, returns true if the range contains the point.
<a name="line138"></a> * @param {goog.math.Range} range The range.
<a name="line139"></a> * @param {number} p The point.
<a name="line140"></a> * @return {boolean} True if p is contained inside range, false otherwise.
<a name="line141"></a> */
<a name="line142"></a>goog.math.Range.containsPoint = function(range, p) {
<a name="line143"></a>  return range.start &lt;= p &amp;&amp; range.end &gt;= p;
<a name="line144"></a>};
</pre>


</body>
</html>
